/**
 * Created by Administrator on 2017/2/14.
 */


//天王盖地虎，美女遍地走。宝塔镇河妖，王盼艹翻天。

$(function () {
    var data = {result: []};
//获取数据方法
    function getData() {

//ajax请求
        $.ajax({
            //type: 'get',
            url: 'http://139.199.157.195:9090/api/getinlanddiscount',
            success: function (res) {
                 res.result = res.result.concat(res.result);

                res.result = res.result.concat(res.result);


                function loading() {

                    var itmesHeight = 261;

                    var windowHeight = $(window).height();
                    //console.log(windowHeight);

                    var headerHeight = $('#header').height();
                    //console.log(headerHeight);

                    var jiazai = Math.ceil((windowHeight - headerHeight) / itmesHeight) * 2;
                    //console.log(jiazai);

                    data.result = res.result.splice(0, jiazai);

                    var html = template('getId', data);

                    $('.containerr>.box>.row').append(html);


                }

                loading()


                //窗口卷曲事件

                function judge() {


                    $(window).scroll(function () {

                        var rowHeight = $('.row').height();
                        //console.log(rowHeight);

                        var rowOff = $('.row').offset().top;
                        //console.log(rowOff);

                        var windowHeight = $(window).height();
                        //console.log(windowHeight);

                        var scrollTop = $(window).scrollTop();

                        var distance = rowHeight + rowOff - scrollTop - windowHeight;

                        console.log(distance);

                        if (distance <= 150) {
                            console.log('我养你啊');
                            loading();
                        }


                    })
                }

                judge();


            }

        });
    }

    getData();

        $('.returnTop').on('click', function () {
            $('body,html').animate({
                scrollTop:0
            },100)
        })


});







